
<script>
    common.setMainTitle('Tin nhắn được gửi tới từ trang LIÊN HỆ');
</script>
<form id="mainform" name='frmviewContact' method=post action="">
    <table style="margin-top: 10px" border="0" width="100%" cellpadding="0" cellspacing="0" id="product-table">
        <thead>
            <tr class="alternate-row">
                <th width="5%" style="text-align: center" nowrap valign="left">
                    <input type="checkbox" name="DELLALL" onclick="checkall(this,'DEL')" >
                </th>
                <th width="350px" style="text-align: left;">Tiêu đề</th>
                <th width="600px" style="text-align: left;">Nội dung</th>
                <th width="" style="text-align: left">Email</th>
                <th width="" style="text-align: left">Ngày gửi</th>
            </tr>
        </thead>
        <tfoot>
        </tfoot>
        <tbody>
       <?php
           
            foreach($this->data as $item){
      ?>
            <tr>
               	<td style="text-align: center">
                    <input id="<?=$item['ID_CONTACT']?>" type="checkbox" name="DEL[]" value="<?=$item['ID_CONTACT']?>" onclick=""/>
                </td>
                <td>
                		<?php
                			$style = array(
                				0 => 'font-weight:bold',
                				1 => 'font-weight:normal'
                			);                			
                		?>
                		<a style="<?=$style[$item['ISREAD']]?>" onClick="viewmessages('<?=$item['ID_CONTACT']?>')"><?php echo Plugin::cutTitle($item['TITLE'],50) ?></a>
                			
                </td>
                <td> 
                		<a style="<?=$style[$item['ISREAD']]?>" onClick="viewmessages('<?=$item['ID_CONTACT']?>')"><?php echo Plugin::cutTitle($item['CONTENT'],80) ?></a>
                </td>
                <td> 
                        <?=$item['EMAIL'];?>
                </td>
                <td> 
                        <?php
                        $datetime = explode(" ",$item['SENT_DATE']);
                        echo common::convertToCultureDate($datetime[0]); echo " ".$datetime[1];
                        ?>
                </td>
                
            </tr>
           
        </tbody>
     <?php } ?>
    </table>
</form>
<script>
 //Gui thong tin status len server
    function viewmessages(id){
    	common.loadAjaxPushState('/contact/admin/view/id/'+id);
    }
    function checkall(selobj,childobj){
        var arr = document.getElementsByName(childobj+"[]");
        for(var i=0;i<arr.length;i++){
         	arr[i].checked = selobj.checked;
        }
    }	
   function del(){
          var ln = 0;
          var arr = document.getElementsByName('DEL[]');
          
          for(var i = 0 ; i < arr.length ;i++ ){
             if(arr[i].checked == true){
                 ln = 1;
                 break;
             }
          }
          if(ln == 1)
          {
        	  if(confirm('Bạn có muốn xóa không'))
           	  {
            	  document.frmviewContact.action= "/contact/admin/delete";
                  document.frmviewContact.method= "POST";
                  common.submitForm(document.frmviewContact,"completeDelete")
	          } 
	          
          }
          else{
              alert("Bạn phải một dòng chọn để xóa");
      	  }
  }
	
	function completeDelete(){
		if(result == '1'){
			common.loadAjax('contact/admin/index');
		}
	}
</script>